﻿using CuocChienQueNha.Class.Basic;
using CuocChienQueNha.Class.File;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;

namespace CuocChienQueNha.Class.MainMap
{
    class TopicMap : ButtonGame
    {
        private Texture2D imgStar, imgLock;
        private int curStar;
        private int totalStar;
        public bool isOpen { get; set; }
        public TopicMap(string name, string link, Vector2 position, Vector2 size, float scale)
        {
            this.name = name;
            this.linkImg = link;
            this.position = position;
            this.size = size;
            this.scale = scale;
            isTouched = false;
            isEnable = true;
        }
        public override void Load(ContentManager content)
        {
            image = content.Load<Texture2D>(linkImg);
            imgStar = content.Load<Texture2D>("Images/MainMap/star");
            imgLock = content.Load<Texture2D>("Images/MainMap/Lock");
        }
        public void Draw(SpriteBatch sprite, SpriteFont font, Vector2 dolech)
        {
            sprite.Draw(image, position - (isTouched ? new Vector2(size.X / 2, size.Y) * 0.1f : Vector2.Zero) + dolech, new Rectangle(0, 0, (int)size.X / 2, (int)size.Y), Color.White, 0f, Vector2.Zero, (isTouched ? scale + 0.2f : scale), SpriteEffects.None, 0);
            if (!isOpen)
            {
                sprite.Draw(imgLock, position + new Vector2(75, 100) + dolech, new Rectangle(0, 0, 82, 99), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
            }
            else
            {
                sprite.Draw(imgStar, position + new Vector2(65, 200) + dolech, new Rectangle(0, 0, 32, 32), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
                sprite.DrawString(font, curStar + "/" + totalStar, position + new Vector2(95, 200) + dolech, Color.White);
            }
        }
        public bool isTouch(Vector2 touch, Vector2 dolech)
        {
            touch -= dolech;
            return isTouch(touch);
        }
        public void getElement(List<LevelStruct> levels)
        {
            int index = Convert.ToInt16(name);
            curStar = 0;
            totalStar = 0;
            isOpen = false;
            foreach (LevelStruct mini in levels)
            {
                if (mini.bando == index)
                {
                    curStar += mini.star;
                    totalStar += 3;
                    if (mini.isOpen) isOpen = true;
                }
            }
        }
    }
}
